package com.yunwaikeji.gy_tool_library.mvvm.view.fragment

import android.os.Bundle
import android.view.View
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener
import com.yunwaikeji.gy_tool_library.mvvm.viewmodel.GYViewModel
import com.yunwaikeji.gy_tool_library.widget.recycler.GYAdapterRefresh

abstract class GYRefreshFragment<Model, ViewModel : GYViewModel> : GYApiFragment<ViewModel>() {
    open val mAdapterRefresh = GYAdapterRefresh<Model>()

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        mAdapterRefresh.setLoadingLayout(mViewAdmin.loadingLayout)
            .setSmartRefreshLayout(mViewAdmin.smartRefreshLayout)
        mAdapterRefresh.smartRefreshLayout.setOnRefreshLoadMoreListener(object :
            OnRefreshLoadMoreListener {
            override fun onRefresh(refreshLayout: RefreshLayout) {
                initData(true)
            }

            override fun onLoadMore(refreshLayout: RefreshLayout) {
                initData(false)
            }
        })
        super.onViewCreated(view, savedInstanceState)
    }
}